<template>
	<view class="content">
		<scroll-view class="scroll" scroll-y>
			<view class="scroll-content">
				<view class="introduce-section">
					<text class="title">{{detailData.title}}</text>
					<view class="introduce">
						<text>{{applicationConfig.appicationName}}</text>
						<text>{{detailData.numberOfReading}}阅读</text>
						<text>{{detailData.publishTime.replace(/T/," ").split(".")[0]}}</text>
					</view>
					<view class="img_box" v-if="detailData.coverImageUrl!= ''">
						<image mode="widthFix" :src="detailData.coverImageUrl" class="activity_img"></image>
					</view>
					<uParse :content="detailData.content" noData=""></uParse>
				</view>
				<view class="container" v-show="loading === false">
					<!-- 推荐 -->
					<view v-if="flag == 1">
						<view class="s-header">
							<text class="tit">相关推荐</text>
						</view>
						<view class="rec-section" v-for="item in newsList" :key="item.articleUuid">
							<view class="rec-item" @click="navToDetails(item)">
								<view class="left">
									<text class="title">{{item.title}}</text>
									<view class="bot">
										<text class="author">{{applicationConfig.applicationName}}</text>
										<text class="time">{{item.publishTime.split("T")[0]}}</text>
									</view>
								</view>
								<view class="right">
									<image class="img" :src="item.coverImageUrl || noPhoto" mode="aspectFill"></image>
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- 加载图标 -->
				<mixLoading class="mix-loading" v-if="loading"></mixLoading>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import json from '@/Json';
	import mixLoading from '@/components/mix-loading/mix-loading';
	import htmlParser from '@/config/html-parser'
	import uParse from '@/components/u-parse/u-parse.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		components: {
			mixLoading,
			uParse
		},
		data() {
			return {
				loading: true,
				communityId:this.$api.util.getAreaCode(),
				detailData: {
					title:'',
					numberOfReading:'',
					publishTime:'',
					coverImageUrl:'',
					htmlNodes:[]
				},
				newsList: [],
				evaList: [],
				tagName: [],
				flag: '',
				id: '',
				noPhoto:"https://cdjjyl.com.cn/images/noPhoto.png"
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'footPrint', 'applicationConfig'])
		},
		onLoad(options) {
			// console.log(options)
			// console.log(options.query)
			// const eventChannel = this.getOpenerEventChannel();
			// this.tagName = eventChannel;
			// let that = this;
			// 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
			// eventChannel.on('login', function(params) {
			//         let {examineList, station, stationList} = params;
			//         that.examineList = examineList;
			//         that.station = station;
			//         that.stationList = stationList;
			//       })
			this.id = options.id;
			this.loadNewsDetail(this.id);
			this.flag = options.flag
			// this.loadNewsList();
		},
		methods: {
			// 获取推荐列表
			// loadNewsList(){
			// 	let list = await json.newsList;
			// 	setTimeout(()=>{
			// 		list.sort((a,b)=>{
			// 			return Math.random() > .5 ? -1 : 1; //静态数据打乱顺序
			// 		})
			// 		list.length = 5;
			// 		list.forEach(item=>{
			// 			this.newsList.push(item);
			// 		})
			// 		this.loading = false;
			// 	}, 1000)
			// },
			loadNewsList(tagName) {
				let that = this;
				this.$api.request.articleList({
					tagDTO: {
						tagName: tagName
					},
					startIndex: 0,
					pageSize: 5,
					areaCode: this.communityId
				}, function(res) {
					if (res.body.status.statusCode === '0') {
						that.newsList = res.body.data.articles;
						that.loading = false;
						for (var i = 0; i < that.newsList.length; i++) {
							if (that.newsList[i].articleUuid == that.id) {
								that.newsList.splice(i, 1)
							}
						}

					}
				},true)
			},
			//获取文章详情
			loadNewsDetail(id) {
				let that = this;
				this.$api.request.articleInfo({
					articleUuid: id
				}, function(res) {
					if (res.body.status.statusCode === '0') {
						that.detailData = res.body.data;
						that.loadNewsList(that.detailData.tagDTO.tagName);
					}
				},true)
			},
			//新闻详情
			navToDetails(item) {
				console.log(item);
				let url = '';
				if (item.articleType === '1' && item.linkType == '自定义内容')
					url = '/package_biz/pages/content/details?id=' + item.articleUuid + '&flag=' + 0;
				if (item.articleType === '1' && item.linkType == '外部链接')
					url = '/package_biz/pages/content/webView?src=' + item.content;
				if (item.articleType === '2' || item.articleType === '3')
					url = '/package_biz/pages/content/videoDetails?id=' + item.articleUuid;
				uni.navigateTo({
					url: url,
				})
			},

		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.content {
		display: flex;
		flex-direction: column;
		height: 100%;
		background: #fff;
	}

	.video-wrapper {
		height: 422upx;

		.video {
			width: 100%;
			height: 100%;
		}
	}

	.scroll {
		flex: 1;
		position: relative;
		background-color: $page-color-base;
		height: 0;
	}

	.scroll-content {
		display: flex;
		flex-direction: column;
	}

	/* 简介 */
	.introduce-section {
		display: flex;
		flex-direction: column;
		padding: 20upx 30upx;
		background: #fff;
		line-height: 1.5;

		.title {
			font-size: 36upx;
			color: #303133;
			margin-bottom: 16upx;
		}

		.introduce {
			display: flex;
			font-size: 26upx;
			color: #909399;

			text {
				margin-right: 16upx;
			}
		}
	}

	.img_box {
		text-align: center;
		margin-bottom: 16upx;
		// border-radius: 10upx;
		// background-color: #666666;
		// height: 300upx;
	}

	.activity_img {
		width: 100%;
		height: 100%;
		border-radius: 10upx;
	}

	/* 点赞等操作 */
	.actions {
		display: flex;
		justify-content: space-around;
		align-items: center;
		line-height: 1.3;
		padding: 10upx 40upx 20upx;

		.action-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			font-size: 24upx;
			color: #999;
		}

		.yticon {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 52upx;

			&.reverse {
				position: relative;
				top: 6upx;
				transform: scaleY(-1);
			}

			&.active {
				color: #ec706b;
			}
		}

		.icon-fenxiang2 {
			font-weight: bold;
			font-size: 36upx;
		}

		.icon-shoucang {
			font-size: 44upx;
		}
	}

	.s-header {
		padding: 20upx 30upx;
		font-size: 30upx;
		color: #303133;
		background: #fff;
		margin-top: 16upx;

		&:before {
			content: '';
			width: 0;
			height: 40upx;
			margin-right: 24upx;
			border-left: 6upx solid #ec706b;
		}
	}

	/* 推荐列表 */
	.rec-section {
		background-color: #fff;

		.rec-item {
			display: flex;
			padding: 20upx 30upx;
			position: relative;
			margin-bottom: 20upx;

			&:after {
				content: '';
				position: absolute;
				left: 30upx;
				right: 0;
				bottom: 0;
				height: 0;
				border-bottom: 1px solid #eee;
				transform: scaleY(50%);
			}
		}

		.left {
			flex: 1;
			padding-right: 10upx;
			overflow: hidden;
			position: relative;
			padding-bottom: 52upx;

			.title {
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				font-size: 32upx;
				color: #303133;
				line-height: 44upx;
			}

			.bot {
				position: absolute;
				left: 0;
				bottom: 4upx;
				font-size: 26upx;
				color: #909399;
			}

			.time {
				margin-left: 20upx;
			}
		}

		.right {
			width: 220upx;
			height: 140upx;
			flex-shrink: 0;
			position: relative;

			.img {
				width: 100%;
				height: 100%;
			}

		}
	}

	/* 评论 */
	.evalution {
		display: flex;
		flex-direction: column;
		background: #fff;
		padding: 20upx 0;
	}

	.eva-item {
		display: flex;
		padding: 20upx 30upx;
		position: relative;

		image {
			width: 60upx;
			height: 60upx;
			border-radius: 50px;
			flex-shrink: 0;
			margin-right: 24upx;
		}

		&:after {
			content: '';
			position: absolute;
			left: 30upx;
			bottom: 0;
			right: 0;
			height: 0;
			border-bottom: 1px solid #eee;
			transform: translateY(50%);
		}

		&:last-child:after {
			border: 0;
		}
	}

	.eva-right {
		display: flex;
		flex-direction: column;
		flex: 1;
		font-size: 26upx;
		color: #909399;
		position: relative;

		.zan-box {
			display: flex;
			align-items: base-line;
			position: absolute;
			top: 10upx;
			right: 10upx;

			.yticon {
				margin-left: 8upx;
			}
		}

		.content {
			font-size: 28upx;
			color: #333;
			padding-top: 20upx;
		}
	}

	/* 底部 */
	.bottom {
		flex-shrink: 0;
		display: flex;
		align-items: center;
		height: 90upx;
		padding: 0 30upx;
		box-shadow: 0 -1px 3px rgba(0, 0, 0, .04);
		position: relative;
		z-index: 1;

		.input-box {
			display: flex;
			align-items: center;
			flex: 1;
			height: 60upx;
			background: #f2f3f3;
			border-radius: 100px;
			padding-left: 30upx;

			.icon-huifu {
				font-size: 28upx;
				color: #909399;
			}

			.input {
				padding: 0 20upx;
				font-size: 28upx;
				color: #303133;
			}
		}

		.confirm-btn {
			font-size: 30upx;
			padding-left: 20upx;
			color: #0d9fff;
		}
	}
	
	.mix-loading{
		transform: translateY(140upx);
	}
</style>
